<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function getRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1) + N)
    }
    let random = getRandom(1, 10)
    // console.log(random)
    let count = 0
    while (1) {
      let input = +prompt('请输入数字')
      if (input > random) {
        count++
        alert(`猜大了，还有${3 - count}次机会`)

      } else if (input < random) {
        count++
        alert(`猜小了，还有${3 - count}次机会`)

      } else {
        alert('猜对了')
        break
      }
      if (count == 3) {
        alert('三次机会用完了')
        break
      }
    }


  </script>
</body>

</html>